//创建一个变量让他自增十万次
class Counter {
    public static int COUNT;

    //静态方法上锁
    public synchronized static void increase() {

        COUNT++;

    }

    //普通方法上锁
    public synchronized void methond() {

    }

    //对代码块上锁
    public void method() {
        synchronized (this) {

        }
     }


     //静态等价的写法
     public synchronized static void fun1() {

     }

     public static void fun2(){
        synchronized(Counter.class) {

        }
    }

    //普通方法等价的写法         实际上都是对对象进行上锁
    public synchronized void fun3() {

    }

    public void fun5(){
        synchronized(this) {

        }
    }

}

public class TestDemo {


    public static void main(String[] args) {
        Counter count = new Counter();
        Thread t = new Thread(()-> {
            for (int i = 0; i < 5_0000; i++) {
                count.increase();
            }
        });

        Thread t1 = new Thread(()-> {
            for (int i = 0; i < 5_0000; i++) {
                count.increase();
            }
        });

        t1.start();
        t.start();

        try {
            t.join();
            t1.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(count.COUNT);
    }
}
